package com.ry.day1129;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;


public class Test {
    public static void main(String[] args) {
        String ipAddress = "10.32.25.17";
        int port = 8080;
        boolean isReachable = isReachable(ipAddress, port);
        if (isReachable) {
            System.out.println("与IP地址 " + ipAddress + " 连通");
        } else {
            System.out.println("与IP地址 " + ipAddress + " 无法连通");
        }

    }


    public static boolean isReachable(String ipAddress, int port) {
        try (Socket socket = new Socket()) {
            socket.connect(new InetSocketAddress(ipAddress, port), 5000); // 超时时间为5秒
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}
